package com.hodgepodge.web.api;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.hodgepodge.api.service.TagService;
import com.hodgepodge.commons.base.entity.PageInfo;
import com.hodgepodge.commons.base.entity.Result;
import com.hodgepodge.commons.entity.Tag;
import com.hodgepodge.commons.validator.group.Query;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 * 标签表 Web接口
 * </p>
 *
 * @author jiangjian
 * @since 2021-02-04
 */
@RestController
@RequestMapping(value = "web/tag")
@Api(tags = "标签接口-web")
public class TagApi {

    @Resource
    private TagService tagService;

    /**
     * 根据条件分页查询标签信息
     *
     * @param pageInfo 分页参数
     * @return 响应结果
     * @author jiangjian
     * @date 2021-06-01
     */
    @ApiOperation(value = "根据条件分页查询标签信息", notes = "根据条件分页查询标签信息")
    @PostMapping("getPageByCondition")
    public Result<List<Tag>> getTagById(@RequestBody @Validated(Query.class) PageInfo<Tag> pageInfo) {
        Page<Tag> page = new Page<>(pageInfo.getCurrentPage(), pageInfo.getPageSize());
        LambdaQueryWrapper<Tag> wrapper = new LambdaQueryWrapper<>(pageInfo.getCondition());
        page = tagService.page(page, wrapper);
        return Result.success(page.getRecords());
    }
}
